package mysql

import (
	"gorm.io/gorm"
)

type Hospital struct {
	gorm.Model
	HospitalName     string `gorm:"type:varchar(50);not null;comment:'医院名称'"`
	HospItalInter    string `gorm:"type:varchar(100);not null;comment:'医院简介'"`
	HospItalAddress  string `gorm:"type:varchar(50);not null;comment:'医院地址'"`
	HospitalType     string `gorm:"type:varchar(20);not null;comment:'医院类型'"`
	HospitalImage    string `gorm:"type:varchar(100);not null;comment:'医院图片'"`
	HospitalFeaTrues string `gorm:"type:varchar(50);not null;comment:'医院特色科室'"`
}

func HospitalList(pages, size int, hospitalName string) (result []*Hospital, err2 error) {
	page := pages
	if page <= 0 {
		page = 1
	}

	pageSize := size
	switch {
	case pageSize > 100:
		pageSize = 100
	case pageSize <= 0:
		pageSize = 10
	}

	offset := (page - 1) * pageSize
	tx := DB.Debug()
	if hospitalName != "" {
		tx = tx.Where("hospital_name Like ?", "%"+hospitalName+"%")
	}
	err2 = tx.Offset(offset).Limit(pageSize).Find(&result).Error
	if err2 != nil {
		return nil, err2
	}
	return
}
func HospitalShow(id int) (result *Hospital, err2 error) {
	DB.Debug().Where("id = ?", id).Limit(1).Find(&result)
	return
}
